import {
    goods
} from "../../goods.js"

Page({
    data: {
        list: goods
    },

    onLoad: function (e) {
        console.log(e);
        var id = e.id;
        console.log(id);
        for (var i = 0; i < this.data.list.length; i++) {
            var good = this.data.list[i];
            if (id == good.id) {
                this.setData({
                    good: good
                });
                break;
            }
        }
        this.loadOrder();
    },
    loadOrder: function (e) {
        var orders = wx.getStorageSync('orders');
        var newOrders = [];
        var totalPrice = 0;

        for (var i = 0; i < orders.length; i++) {
            var order = orders[i];
            totalPrice += order.price * order.num;
            newOrders.push(order);
        }
        wx.setStorageSync('orders', newOrders);
        this.setData({
            totalPrice: totalPrice,
            orders: newOrders
        });
    },
    success: function (e) {
        wx.showToast({
            title: '已支付',
            icon: 'success',
            duration: 2000
        });
    }
    
})